/*
 * @Author: Ma Yuchen
 * @Date: 2021-12-22 13:50:33
 * @LastEditors: Ma YuChen
 * @LastEditTime: 2023-08-02 16:20:00
 * @Description: file content
 * @FilePath: \video-repeater-ctl-mcu\bsp_i2c\bsp_i2c.h
 */

#ifndef BSP_I2C_H_
#define BSP_I2C_H_
#include <gd32f10x_gpio.h>              // GigaDevice::Device:GD32F10x_StdPeripherals:GPIO
#include <gd32f10x_rcu.h>               // GigaDevice::Device:GD32F10x_StdPeripherals:RCU



/**************************I2C 参数定义， I2C1 或 I2C2*********************/
/* STM32 I2C 快速模式400000   慢速100000 */
#define I2C_Speed							100000

/* 主机配置 */
#define MASTER_I2C1							I2C1
#define MASTER_I2C1_APBxClock_FUN			rcu_periph_clock_enable
#define MASTER_I2C1_CLK						RCU_I2C1
#define MASTER_I2C1_GPIO_APBxClock_FUN		rcu_periph_clock_enable
#define MASTER_I2C1_GPIO_CLK					RCU_GPIOB
#define MASTER_I2C1_SCL_PORT					GPIOB
#define MASTER_I2C1_SCL_PIN					GPIO_PIN_10
#define MASTER_I2C1_SDA_PORT					GPIOB
#define MASTER_I2C1_SDA_PIN					GPIO_PIN_11

#define MASTER_I2C1_OWN_ADDRESS7 			0X0A

#define MASTER_I2C2							I2C0
#define MASTER_I2C2_APBxClock_FUN			rcu_periph_clock_enable
#define MASTER_I2C2_CLK						RCU_I2C0
#define MASTER_I2C2_GPIO_APBxClock_FUN		rcu_periph_clock_enable
#define MASTER_I2C2_GPIO_CLK					RCU_GPIOB
#define MASTER_I2C2_SCL_PORT					GPIOB
#define MASTER_I2C2_SCL_PIN					GPIO_PIN_6
#define MASTER_I2C2_SDA_PORT					GPIOB
#define MASTER_I2C2_SDA_PIN					GPIO_PIN_7

#define MASTER_I2C2_OWN_ADDRESS7 			0X0A

/* 通讯等待超时时间 */
#define I2CT_FLAG_TIMEOUT           ((uint32_t)0x100)
#define I2CT_LONG_TIMEOUT           ((uint32_t)0x1000)

#define I2C_Process_OK                                       0
#define I2C_ERR_MASTER_MODE_SELECT_OVERTIME                 -1
#define I2C_ERR_MASTER_TRANSMITTER_MODEL_SELECT_OVERTIME    -2
#define I2C_ERR_MASTER_BYTE_TRANSMIT_OVERTIME               -3
#define I2C_ERR_MASTER_SELECT                               -4


void MASTER_I2C_Init(void);
uint8_t I2C_Master_BufferWrite(uint32_t I2Cx, uint8_t* pBuffer, uint32_t NumByteToWrite, uint8_t SlaveAddress);
uint8_t I2C_Master_BufferRead(uint32_t I2Cx, uint8_t* pBuffer, uint32_t NumByteToRead, uint8_t SlaveAddress);
extern uint8_t  Flag_RcvOK_IIC;
void printIIC2Recv(void);

#endif //BSP_I2C_H_
